<?php
/*
 * admin888 <paven@gmail.com>
 * Description : Controller thao tác giao diện index 
 */
class IndexController extends Zend_Controller_Action
{
	
	/*
	 * admin888 <doan.hut@gmail.com>
	 * Description : dùng chung cho action
	 * 
	 */
	protected  $_uid = 'null';
	
    public function init()
    {
       //phần lay out trên 
       $auth = Zend_Auth::getInstance();
	  if($auth->hasIdentity()){
			$data = $auth->getIdentity();
			$this->view->name = $data->name;
			$this->view->iddangnhap = $data->uid;
			$this->_uid = $data->uid;
			$cd = new Model_Caidat();
			$thongbao = $cd->getthongbao($data->uid);
			$this->view->thongbao = $thongbao;
	   }
       $reponse = $this->getResponse();
       $reponse->insert('top', $this->view->render('index/top.phtml'));
       $this->view->title = " Dashboard Pro - Email Manager ";
    }
    /**
     * admin888 <doan.hut@gmail.com>
     * Description : check nếu chưa login thì chuyển về trang ngoài
     * Note hàm này mọi người có thể dung chung
     */
	public function preDispatch() {
	    $auth = Zend_Auth::getInstance();
	    if (!$auth->hasIdentity()) {
	        if ($this->_request->getActionName() != 'login') {
	            $this->_redirect('login');
	        }
	    }
	}
    /**
     * admin888 <paven@gmail.com>
     * Enter description : logout khi nguoi dung logout
     */
	public function logoutAction() {
	    $auth = Zend_Auth::getInstance();
	    $auth->clearIdentity();
	    $this->_redirect('login');
	    $this->getHelper('viewRenderer')->setNoRender();
	}
    /**
     * admin888 <paven@gmail.com>
     * Enter description : Action index là điều khiển chính
     */
	public function indexAction()
    {
          require_once 'public/scripts/functionchat/include/FusionCharts.php';
          // laay data  bieu do lien lien he 
          $lh = new Model_Lienhe();
          $nhom = $lh->getnhomluid($this->_uid);
         foreach ($nhom as $key => $value){
         	$nhom[$key]['tonglienhe'] = $lh->demlienhe($value['id_nlh']);
         }
        $this->view->thonhkenhonlh = $nhom;
        // lay data cho biểu đồ thư
        $thu = new Model_Thudagui();
        $thumau = new Model_Thumau();
        $thudagui = $thu->demthu($this->_uid,1);
        $thunhap = $thu->demthu($this->_uid,0);
        $thumau = $thumau->demthuaum($this->_uid);
        $this->view->thumau = $thumau;
		$this->view->thudagu = $thudagui;
		$this->view->thunhap = $thunhap;
		// lay lien hệ quan trọng 
		$lienheghichu = $lh->getalllienheghichu($this->_uid);
		$this->view->lienhedb= $lienheghichu;
		//lay thu da gui 
		$gt =new Model_Thudagui();
		$dulieu = $gt->getallthudaguidb($this->_uid,1); // chua co cache se load trong db 
		$this->view->thudagui = $dulieu;
	

    }
    public function docthongbaoAction()
    {
    	$tb = new Model_Caidat();
    	$doctb = $tb->docthongbaobd($this->_uid);
    	if($doctb){
    		$this->_redirect('caidat');
    	}else{
    		$this->_redirect('index');
    	}
        
    	$this->getHelper('viewRenderer')->setNoRender(); // set khong su dung template
        $this->_helper->layout->disableLayout(); //disable layout
    }

    


}
